package com.bestillet.kyllingogco;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Application;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

public class ShopApplication extends Application {
	private LruCache<String, Bitmap> cache;
	
	private ArrayList<Category> categories;
	private ArrayList<Shop> shops;
	private ArrayList<Card> cards;
	
	private Shop shop;
	
	private int kundeId, basketId;
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		categories = new ArrayList<Category>();
		shops = new ArrayList<Shop>();
		cards = new ArrayList<Card>();
		
		final int max = (int) (Runtime.getRuntime().maxMemory() / 1024);
	    final int size = max / 8;
	    cache = new LruCache<String, Bitmap>(size) {
	        @SuppressLint("NewApi")
			@Override
	        protected int sizeOf(String key, Bitmap bitmap) {
	        	if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2)
	                return bitmap.getByteCount() / 1024;
	            else
	                return (bitmap.getRowBytes() * bitmap.getHeight()) / 1024;
	        }
	    };
	}

	public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
	    if (getBitmapFromMemCache(key) == null)
	        cache.put(key, bitmap);
	}
	
	public void removeBitmapFromMemoryCache(String key) {
		if (getBitmapFromMemCache(key) != null)
			cache.remove(key);
	}
	
	public Bitmap getBitmapFromMemCache(String key) {
	    return cache.get(key);
	}
	
	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	public int getKundeId() {
		return kundeId;
	}

	public void setKundeId(int kundeId) {
		this.kundeId = kundeId;
	}

	public int getBasketId() {
		return basketId;
	}

	public void setBasketId(int basketId) {
		this.basketId = basketId;
	}

	public ArrayList<Category> getCategories() {
		return new ArrayList<Category>(categories);
	}
	
	public void clearCategories() {
		categories.clear();
	}
	
	public void addCategories(ArrayList<Category> categories) {
		this.categories.addAll(categories);
	}

	public ArrayList<Shop> getShops() {
		return new ArrayList<Shop>(shops);
	}
	
	public void clearShops() {
		shops.clear();
	}
	
	public void addShops(ArrayList<Shop> shops) {
		this.shops.addAll(shops);
	}

	public ArrayList<Card> getCards() {
		return new ArrayList<Card>(cards);
	}
	
	public void clearCards() {
		cards.clear();
	}
	
	public void addCards(ArrayList<Card> cards) {
		this.cards.addAll(cards);
	}
}